function output = eu_ug(pm,r,theta,str,y)

% Computes the expected utility for a UG protocol

% pm is a 5x1 vector of parameters, pm = (alpha,beta,kappa,delta,gamma),
% r is the crra parameter
% theta contains the monetary payoffs theta = (T,R,P,S)
% str contains the pure strategy
% y contains the beliefs y = (y1,y2) 

alpha = pm(1); beta = pm(2); kappa = pm(3); delta = pm(4); gamma = pm(5);

% transform the strategy number to (x1,x2)
allx = ff2n(2);
x = allx(5-str,:);
    
if r==1 
   pi = log(theta);
else
   pi = (1/(1-r))*(theta.^(1-r)-1);
end

eu = (1-kappa)*(x(1)*pi(2)+(1-x(1))*y(2)*pi(1)+(1-x(1))*(1-y(2))*pi(4)...
    +y(1)*pi(2)+(1-y(1))*x(2)*pi(3)+(1-y(1))*(1-x(2))*pi(4))...
    -(alpha*(1-y(1))*x(2)+beta*(1-x(1))*y(2))*(pi(1)-pi(3))...
    +kappa*(x(1)*pi(2)+(1-x(1))*x(2)*pi(1)+(1-x(1))*(1-x(2))*pi(4)...
    +x(1)*pi(2)+(1-x(1))*x(2)*pi(3)+(1-x(1))*(1-x(2))*pi(4))...
    -delta*((1-y(1))*x(2)*(pi(1)-pi(3)));

output = eu;